package com.service.impl;

import com.dao.EmpDao;
import com.entity.EmpEntity;
import com.service.EmpService;
import com.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpDao empDao;
    @Autowired
    private RedisService redisService;
    @Override
    public List<EmpEntity> getAll(int pageNum, int pageSize) {
        List<EmpEntity> list = null;
        Object cachedEmps = redisService.get("emp:" + pageNum);
        if(cachedEmps!=null){
            System.out.println("=====从缓存中取得数据=====");
            list = (List<EmpEntity>) cachedEmps;
            return list;
        }else {
            System.out.println("====从缓存中娶不到数据=== 从db中取");
            list = empDao.getAll(pageNum, pageSize);
            redisService.set("emp:" + pageNum,list);
        }
        return list;
    }
}
